package client

import (
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/registry"
	"github.com/micro/go-plugins/registry/consul/v2"
	"gomicrodemo/proto/goods"
)

var goodClient goods.GoodService

func GetGoodClient() goods.GoodService {

	if goodClient == nil {
		consulRegistry := consul.NewRegistry(
			registry.Addrs("127.0.0.1:8500"),
		)

		service := micro.NewService(
			micro.Registry(consulRegistry),
		)
		goodClient = goods.NewGoodService("changgou-goods", service.Client())
	}

	return goodClient
}

//test
